package com.dianzi.es.rep.service.impl;

import com.dianzi.es.rep.dao.ReportorderDao;
import com.dianzi.es.rep.util.Utils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dianzi.common.utils.PageUtils;
import com.dianzi.common.utils.Query;

import com.dianzi.es.rep.dao.UrgentorderDao;
import com.dianzi.es.rep.entity.UrgentorderEntity;
import com.dianzi.es.rep.service.UrgentorderService;


@Service("urgentorderService")
public class UrgentorderServiceImpl extends ServiceImpl<UrgentorderDao, UrgentorderEntity> implements UrgentorderService {
    @Autowired
    private UrgentorderDao urgentorderDao;
    @Autowired
    private ReportorderDao reportorderDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Object workerId =  params.get("workerId");
        IPage<UrgentorderEntity> page = this.page(
                new Query<UrgentorderEntity>().getPage(params),
                new QueryWrapper<UrgentorderEntity>()
                        .like(workerId!=null,"worker_ids", ","+workerId+",")
                        .orderByDesc("updtime")
        );
        return new PageUtils(page);
    }

    @Override
    public Map<String, Object> getList(Map<String, Object> params) {
        Object workerId = params.get("workerId");
        Object id = params.get("id");
        if(!Utils.isEmpty(workerId)){
            params.put("workerId","%,"+workerId+",%");
        }
        List<Map<String, Object>> list = urgentorderDao.getList(params);
        int count = Utils.isEmpty(id)?urgentorderDao.getListCount(params):1;
        return Utils.makeQueryMap("list",list,"cn",count);
    }

    @Override
    public Map<String, Object> getInfoByOrder(Map<String, Object> params) {
        Map<String,Object> urgentorder = urgentorderDao.getInfoByOrder(params);
        Map<String,Object> reportorder = reportorderDao.getInfoByOrder(params);
        return Utils.makeQueryMap("urgentorder",urgentorder,"reportorder",reportorder);
    }

    @Override
    public void dispatch(Map<String, Object> params) {
        urgentorderDao.dispatch(params);
        reportorderDao.dispatch(params);
    }

}